package com.nuoniu.sibanyun.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;

/**
 * @ClassName LocalDateTimeUtils
 * @Description TODO
 * @Author 白强
 * @Date 2022/6/8 17:18
 * @Version 1.0
 **/
public class LocalDateTimeUtils {
    /**
     * 获取当年第一天
      * @param now
     * @return
     */
    public static LocalDateTime getFirstDayOfYear(LocalDateTime now){
        LocalDateTime firstDayOfYear = LocalDateTime.of(LocalDate.from(now.with(TemporalAdjusters.firstDayOfYear())), LocalTime.MIN);
        return firstDayOfYear;
    }
    /**
     * 获取当年最后一天
     * @param now
     * @return
     */
    public static LocalDateTime getLastDayOfYear(LocalDateTime now){
        LocalDateTime lastDayOfYear = LocalDateTime.of(LocalDate.from(now.with(TemporalAdjusters.lastDayOfYear())), LocalTime.MAX);
        return lastDayOfYear;
    }
    /**
     * 获取当前月第一天
     * @param now
     * @return
     */
    public static LocalDateTime getFirstDayOfMonth(LocalDateTime now){
        LocalDateTime firstDayOfMonth = LocalDateTime.of(LocalDate.from(now.with(TemporalAdjusters.firstDayOfMonth())), LocalTime.MIN);
        return firstDayOfMonth;
    }
    /**
     * 获取当前月最后一天
     * @param now
     * @return
     */
    public static LocalDateTime getLastDayOfMonth(LocalDateTime now){
        LocalDateTime lastDayOfMonth = LocalDateTime.of(LocalDate.from(now.with(TemporalAdjusters.lastDayOfMonth())), LocalTime.MAX);
        return lastDayOfMonth;
    }
    /**
     * 获取当天的开始时间
     * @param now
     * @return
     */
    private static LocalDateTime getFirstTimeOfDay(LocalDateTime now){
        LocalDateTime firstTimeOfDay = LocalDateTime.of(now.toLocalDate(), LocalTime.MIN);
        return firstTimeOfDay;
    }
    /**
     * 获取当天的结束时间
     * @param now
     * @return
     */
    public static LocalDateTime getLastTimeOfDay(LocalDateTime now){
        LocalDateTime lastTimeOfDay = LocalDateTime.of(now.toLocalDate(), LocalTime.MAX);
        return lastTimeOfDay;
    }
}
